/**
 * @Author: easten
 * @Created: 2024-08-09 01:16:06
 * @Description: 角色管理接口
 *
 */
import { SysRole } from "_common/entity";
import { createRequest, RequestMethod } from "_common/request";
import { AxiosInstance } from "axios";
export class ApiRole {
  /**
   * @description 请求实例
   * @type {RequestMethod}
   * @memberof ApiDevice
   * */
  request: RequestMethod;
  url: string = "api/sys/role";

  /**
   * @description 构造函数
   * @param config axios 配置
   */
  public constructor(instance: AxiosInstance) {
    // axios 实例化
    this.request = createRequest(instance);
  }

  createRole(data: SysRole) {
    return this.request.post<boolean>(this.url + "/create", data);
  }

  /** 更新角色 */
  updateRole(data: SysRole) {
    return this.request.put<boolean>(this.url + "/update", data);
  }

  /** 删除角色 */
  deleteRole(id: number) {
    return this.request.delete<boolean>(this.url + "/delete/" + id);
  }

  /** 获取角色信息 */
  getRoleInfo(id: number) {
    return this.request.get<SysRole>(this.url + "/get-role", { id });
  }

  /** 获取角色列表 */
  getRoleList() {
    return this.request.get<SysRole[]>(this.url + "/get-list");
  }

  // 获取角色分页列表
  getPageList(params: any) {
    return this.request.get<any>(this.url + "/get-page", params);
  }

  // 角色授权
  rolePermission(data: any) {
    return this.request.post<boolean>(this.url + "/change-permission", data);
  }

  // 获取角色的权限
  getRolePermission(id: number) {
    return this.request.get<string[]>(this.url + "/get-permission-ids/" + id);
  }
}
